package hu.bme.orarend.server;

import hu.bme.orarend.client.OrarendService;
import hu.bme.orarend.shared.ClassDTO;
import hu.bme.orarend.shared.RoomDTO;
import hu.bme.orarend.shared.ScheduleDTO;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class OrarendServiceImpl extends RemoteServiceServlet implements OrarendService
{
	private static DBConnector db = new DBConnector();

  @Override
  public Boolean saveRoom( RoomDTO roomDTO ) throws Exception
  {
    return db.saveRoom(roomDTO);
  }
  
  public ArrayList<RoomDTO> getRoomList( )
  {
    return db.getRoomList();
  }
  
  public Boolean saveClass( ClassDTO classDTO ) throws Exception
  {
    return db.saveClass( classDTO );
  }

  public ArrayList<ClassDTO> getClassList( )
  {
    return db.getClassList();
  }
  
  public Integer createSchedule()
  {
    return db.createSchedule();
  }
  
  public ArrayList<ScheduleDTO> getScheduleList()
  {
    return db.getScheduleList();
  }
  
  public ArrayList<ClassDTO> getLeftClassesList()
  {
    return db.getLeftClassList();
  }

  @Override
  public Boolean authUser( String user, String passw ) throws NoSuchAlgorithmException
  {
    MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
    digest.update( passw.getBytes() );
    byte[] hash = digest.digest();
    String hashedPassw = new String( hash );
    // TODO ide jön a háttér auth hívás
    return true;
  }
}
